<?php
    // include_once '../../fn.php';
    // header('content-type:text/html;charset=utf-8');
    // 基于$_COOKIE关联$_SESSION，再关联同名文件中存储的id去数据库里找登录的数据
    // 只要请求php页面，基于http协议，$_COOKIE就会传给后台，$_SESSION也就能关联上$_COOKIE

    //session_start();//侧边栏不是一个单独页面是一个页面的模块，主页面开启了session_start()，因此这里不用开启
    // echo '<pre>';
    // print_r($_SESSION['user_id']);
    // echo '</pre>';
    $id = $_SESSION['user_id'];

    // 编辑数据库执行串
    $sql = "select nickname,avatar from users where id='$id '";
    $result = my_query($sql)[0];
    // echo '<pre>';
    // print_r($result);
    // echo '</pre>';
?>

<?php
    // 判断页面是否是文章导航下的二级导航
    $isPosts = in_array($flag,['posts','post-add','categories']);
    // 判断页面是否是设置导航下的二级导航
    $isSettings = in_array($flag,['nav-menus','slides','settings']);
    // 基于浏览器观察、删减类名，基本可以确定改哪些样式能控制二级导航的展开和收缩
?>
<div class="aside" data-userId="<?php echo $id; ?>">
    <div class="profile">
        <img class="avatar" src="../<?php echo $result['avatar']; ?>">
        <h3 class="name"><?php echo $result['nickname']; ?></h3>
    </div>
    <ul class="nav">
        <li <?php echo $flag=='index' ? 'class="active"':'';?>>
            <a href="index1.php"><i class="fa fa-dashboard"></i>仪表盘</a>
        </li>
        <li >
            <a href="#menu-posts" data-toggle="collapse" class=<?php echo $isPosts ? '' :'collapsed' ?>>
                <i class="fa fa-thumb-tack"></i>文章<i class="fa fa-angle-right"></i>
            </a>
            <ul id="menu-posts" class=<?php echo $isPosts ? '"collapse in"' :'collapse' ?>>
                <li <?php echo $flag=='posts' ? 'class="active"':'';?>><a href="posts.php">所有文章</a></li>
                <li <?php echo $flag=='post-add' ? 'class="active"':'';?>><a href="post-add.php">写文章</a></li>
                <li <?php echo $flag=='categories' ? 'class="active"':'';?>><a href="categories.php">分类目录</a></li>
            </ul>
        </li>
        <li <?php echo $flag=='comments' ? 'class="active"':'';?>>
            <a href="comments.php"><i class="fa fa-comments"></i>评论</a>
        </li>
        <li <?php echo $flag=='users' ? 'class="active"':'';?>>
            <a href="users.php"><i class="fa fa-users"></i>用户</a>
        </li>
        <li>
            <a href="#menu-settings" data-toggle="collapse" class=<?php echo $isSettings ? '' :'collapsed' ?>>
                <i class="fa fa-cogs"></i>设置<i class="fa fa-angle-right"></i>
            </a>
            <ul id="menu-settings" class=<?php echo $isSettings ? '"collapse in"' :'collapse' ?>>
                <li <?php echo $flag=='nav-menus' ? 'class="active"':'';?>><a href="nav-menus.php">导航菜单</a></li>
                <li <?php echo $flag=='slides' ? 'class="active"':'';?>><a href="slides.php">图片轮播</a></li>
                <li <?php echo $flag=='settings' ? 'class="active"':'';?>><a href="settings.php">网站设置</a></li>
            </ul>
        </li>
    </ul>
</div>